﻿@using Layui.Entities;
@model Layui.Mvc.Areas.Admin.Models.UserRoleViewModel

<div class="col-sm-12">
    <form asp-route="setUserRole" id="formSetUserRole" onsubmit="return false;" class="form-horizontal">
        @Html.AntiForgeryToken()
        <input type="hidden" id="userId" name="userId" value="@Model.SysUser.Id" />
        <h4 class="widget-title">@(Model.SysUser.Name) [@(Model.SysUser.Account)]</h4>
        <hr />
        <div class="col-sm-12">
            @foreach (var item in Model.RoleList)
            {
                <label>
                    @if (Model.UserRoleList.Any(o => o.RoleId == item.Id))
                    {
                        <input type="checkbox" class="ace" name="roleIds" checked="checked" value="@item.Id" />
                    }
                    else
                    {
                        <input type="checkbox" class="ace" name="roleIds" value="@item.Id" />
                    }
                    <span class="lbl">@item.Name</span>
                </label>
            } 
            <div class="space-10"></div>
            <button class="btn btn-sm btn-primary" type="submit">
                <i class="ace-icon fa fa-check bigger-110"></i>
                提交
            </button>
        </div> 
    </form>
</div>
<script>
    $(function () {
        $.validator.unobtrusive.parse($('#formSetUserRole'));
        $('#formSetUserRole').submit(function (e) {
            if ($(this).valid()) {
                layer.load(2);
                $(this).ajaxSubmit(function (data) {
                    if (data.Status) {
                        location.reload();
                    } else {
                        layer.msg(data.Message, { icon: 2 });
                    }
                });
            }
        });
    });
</script>














